package view.hall
{
	import flash.display.DisplayObject;
	import flash.events.Event;
	import flash.events.TimerEvent;
	
	import utils.EnterFrameTimer;
	import utils.animate.TweenProperty;
	
	import view.face.Hint;
	
	public class SearchPrompt extends Hint
	{
		private var timer:EnterFrameTimer;
		private var tween:TweenProperty;
		
		public function SearchPrompt()
		{
			initTimer();
			initTween();
		}
		
		private function initTween():void
		{
			tween = new TweenProperty();
			tween.duration = 1;
			
		}
		
		private function onComplete(event:Event):void
		{
			tween.removeEventListener(Event.COMPLETE,onComplete);
			timer.start();
		}
		
		
		private function initTimer():void
		{
			timer = new EnterFrameTimer(3000,1);
			timer.addEventListener(TimerEvent.TIMER_COMPLETE,onTimerComplete);
			
		}
		
		private function onTimerComplete(event:TimerEvent):void
		{
			tween.setTarget(this,"alpha",1,0);
			tween.start();
		}
		
		public function update(content:String,target:DisplayObject):void
		{
			content = "<font color='#000000' size= '12'>" + content + "</font>";
			showHint(target,content,true);
			this.y -= 7
			drawArrow();
			
			this.alpha = 0;
			tween.setTarget(this,"alpha",0,1);
			tween.addEventListener(Event.COMPLETE,onComplete);
			tween.start();
		}
		
		public function stop():void
		{
			tween.stop();
			timer.reset();
			this.alpha = 0;
		}
		
		private function drawArrow():void
		{
			with(this.graphics)
			{
				beginFill(0xFFFFFF,.9);
				moveTo(hintText.width * .5 - 7,hintText.height + 2);
				lineTo(hintText.width * .5 + 7,hintText.height + 2);
				lineTo(hintText.width * .5,hintText.height + 14);
				lineTo(hintText.width * .5 - 7,hintText.height + 2);
				endFill();
			}
		}
	}
}